package com.yunche.yunchebusiness.mvp.presenter

import com.yunche.yunchebusiness.base.mvp.BasePresenter
import com.yunche.yunchebusiness.mvp.contract.AddTenantContract
import com.yunche.yunchebusiness.mvp.model.AddTenantModel
import com.yunche.yunchebusiness.network.exception.ErrorStatus
import com.yunche.yunchebusiness.network.exception.ExceptionHandle
import okhttp3.RequestBody

/**
 * Create by Crcker on 2018/12/28 19:07
 * Email: Crcker@163.com
 */


class AddTenantPresenter : BasePresenter<AddTenantContract.View>(), AddTenantContract.Presenter {

    private val model by lazy {
        AddTenantModel()
    }

    override fun getBankList(requestBody: RequestBody) {
        checkViewAttached()
        mRootView?.showLoading()
        var disposable = model.getBankList(requestBody).subscribe({
            mRootView!!.apply {
                hideLoading()
                if (it.resultCode == ErrorStatus.SUCCESS) {
                    getBankListSuccess(it.datas!!)
                } else {
                    showError(it.message!!)
                }
            }
        }, {
            mRootView?.hideLoading()
            mRootView?.showError(ExceptionHandle.handleException(it))
        })
        addSubscription(disposable)
    }

    override fun submit(requestBody: RequestBody,id:String) {
        checkViewAttached()
        mRootView?.showLoading()
        var disposable = model.submit(requestBody,id).subscribe({
            mRootView!!.apply {
                hideLoading()
                if (it.resultCode == ErrorStatus.SUCCESS) {
                    submitSuccess()
                } else {
                    showError(it.message!!)
                }
            }
        }, {
            mRootView?.hideLoading()
            mRootView?.showError(ExceptionHandle.handleException(it))
        })
        addSubscription(disposable)
    }
}